import pandas as pd

data = {
    "Name": ["Alice", "Bob", "Tom"],
    "Age": [22, 23, 24],
    "City": ["Beijing", "Shanghai", "Guangzhou"],
}
df = pd.DataFrame(data)

# 1.保存为csv文件
df.to_csv("data.csv", index=False)
""" data.csv
Name,Age,City
Alice,22,Beijing
Bob,23,Shanghai
Tom,24,Guangzhou

"""

# 2.保存为csv文件, 添加表头
df.to_csv("data2.csv")
""" data2.csv
,Name,Age,City
0,Alice,22,Beijing
1,Bob,23,Shanghai
2,Tom,24,Guangzhou

"""